package com.easyjava.utils;

import java.io.InputStream;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @ClassName: PropertiesUtils
 * @Description: TODO
 * @Version: V1.0.0
 * @Author: LaiAnda
 * @Date: 2025/7/28 16:38
 */
public class PropertiesUtils {
    private static Properties prope = new Properties();
    private static Map<String, String> PROPE_MAP = new ConcurrentHashMap();

    static {
        InputStream is = null;
        try {
            is = PropertiesUtils.class.getClassLoader().getResourceAsStream("application.properties");
            prope.load(is);

            Iterator<Object> iterator = prope.keySet().iterator();
            while (iterator.hasNext()) {
                String key = (String) iterator.next();
                PROPE_MAP.put(key, prope.getProperty(key));
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (is != null){
                try {
                    is.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }

    public static String getString(String  key) {
        return PROPE_MAP.get(key);
    }



    // 测试
    public static void main(String[] args) {
        System.out.println(PropertiesUtils.getString("db.driver-name"));
    }

}